import { baseRequestClient, requestClient } from '#/api/request';

export namespace AuthApi {
  /** 登录接口参数 */
  export interface LoginParams {
    password?: string;
    username?: string;
  }

  /** 登录接口返回值 */
  export interface LoginResult {
    accessToken: string;
    user?: {
      id: number;
      username: string;
      nickname: string;
      avatar: string;
      email: string;
      phone: string;
      status: number;
      lastLoginAt: string;
      lastLoginIP: string;
    };
  }

  export interface RefreshTokenResult {
    accessToken: string;
  }
}

/**
 * 登录接口
 * @param data 登录参数
 */
export async function loginApi(data: AuthApi.LoginParams) {
  return requestClient.post<AuthApi.LoginResult>('/auth/login', data);
}

/**
 * 刷新token接口
 */
export async function refreshTokenApi() {
  return requestClient.post<AuthApi.RefreshTokenResult>('/auth/refresh');
}

/**
 * 登出接口
 */
export async function logoutApi() {
  return requestClient.post<void>('/auth/logout');
}

/**
 * 获取用户权限码
 */
export async function getAccessCodesApi() {
  return requestClient.get<string[]>('/auth/codes');
}
